/**
 * 
 */
package utils;

import java.io.UnsupportedEncodingException;
import java.security.*;

import sun.misc.BASE64Encoder;

/**
 * Classe permettant de crypter une chaine de caracteres.
 * 
 */
public class Crypto {

	public static String encrypt(String plaintext) {
		MessageDigest md = null;
		try {
			md = MessageDigest.getInstance("SHA");
			// step 2
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		try {
			md.update(plaintext.getBytes("UTF-8"));
			// step 3
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		byte raw[] = md.digest();
		// step 4
		String hash = (new BASE64Encoder()).encode(raw);
		// step 5
		return hash;
		// step 6
	}
}
